-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a log buffer to store log messages. #52
base: main
Are you sure you want to change the base?
Conversation
Probably a good idea to rebase from the main branch to fix the cargo fmt checks. Also, make sure your author email matches your Signed-off-by email! EDIT: nevermind, no need for a rebase, but the fmt checks should be fixed. |
sorry, will fix the fmt checks. I was under the impression that commit hook reports the deviations. |
The git hook should warn you, but won't fix the issues automatically. |
26e9a9f
to
5648746
Compare
Reworked the findings so far. |
87b4c26
to
fc7ff02
Compare
Status so far on this PR:
|
c51a833
to
97c017b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided some comments in the reviews. Please also move the logbuffer specific code into a separate sub-directory/module.
|
In this PR:
|
5af0ce1
to
8a5d881
Compare
ecd3216
to
8fce96e
Compare
7476cee
to
3d2c06d
Compare
Rebased the PR to the latest HEAD. |
Needs rebase due to percpu related changes in 7e5a9a7 |
37851c2
to
4e8cd5e
Compare
kernel/src/log_buffer/mod.rs
Outdated
} | ||
|
||
pub fn write_log(&mut self, s: &FixedString<LINE_BUFFER_SIZE>) { | ||
self.buf.write(&s.to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates an intermediate allocation. Perhaps write() should take a generic char
iterator which it can consume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed write() interface to take char iterator as a parameter.
kernel/src/log_buffer/mod.rs
Outdated
// A method used for testing | ||
pub fn read_log(&mut self) -> Vec<u8> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only used for testing gate it behind #[cfg(test)]
to avoid unused warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
kernel/src/log_buffer/mod.rs
Outdated
pub unsafe fn migrate(&mut self, lb: *const SpinLock<LogBuffer>) { | ||
unsafe { | ||
self.buf = (*lb).lock().buf; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not pass a regular reference to the spinlock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, some compilation problems made me use that. But I have changed to use a regular reference now.
kernel/src/log_buffer/mod.rs
Outdated
} | ||
} | ||
|
||
static mut LB: SpinLock<LogBuffer> = SpinLock::new(LogBuffer::new()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it need to be mut
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary. Removed it. Thanks!
kernel/src/log_buffer/mod.rs
Outdated
#[cfg(test)] | ||
const BUF_SIZE: usize = 64; | ||
|
||
#[cfg(test)] | ||
use crate::types::LINE_BUFFER_SIZE; | ||
|
||
#[test] | ||
fn test_read_write_normal() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these should be in a test module, e.g.
#[cfg(test)]
mod test {
use crate::types::LINE_BUFFER_SIZE;
const BUF_SIZE: usize = 64;
#[test]
fn test_read_write_normal() {
// ...
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
// | ||
// Copyright (c) 2022-2024 SUSE LLC | ||
// | ||
// Author: Roy Hopkins <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably forgot to update author name :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually Roy created this file in one of the branches. I cherry picked it to my branch. So I will let it stay. :)
#[test] | ||
fn test_ring_one_string() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test and the ones below should also be in a test module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
kernel/src/cpu/line_buffer.rs
Outdated
|
||
fn log(&self, record: &log::Record<'_>) { | ||
let comp: &'static str = self.component; | ||
let line_buf: &mut LineBuffer = &mut this_cpu().get_line_buffer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to add the type here, RefMut
implements Deref
and DerefMut
, so access to the LineBuffer
methods is transparent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed!
kernel/src/cpu/line_buffer.rs
Outdated
pub fn install_buffer_logger(component: &'static str) { | ||
BUFFER_LOGGER | ||
.init(&BufferLogger::new(component)) | ||
.expect("already initialized the logger"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say return the error here and panic at the caller, just like we had before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
0a410dd
to
ebb7b14
Compare
The log buffer is implemented using a ring buffer that contains the characters within log entries. This patch introduces a generic StringRingBuffer that can be used for safely managing the contents of strings within a ring buffer that is suitable for use with the log buffer. This separates the ring buffer implementation from the log and allows implementation of ring buffer specific unit testing, which is included within this patch. Signed-off-by: Vasant Karasulli <[email protected]> Signed-off-by: Roy Hopkins <[email protected]>
This log buffer is based on the string ring buffer in utils/StringRingBuffer. Signed-off-by: Vasant Karasulli <[email protected]>
Each individual log message gets written into the global log buffer from the percpu line buffer. Signed-off-by: Vasant Karasulli <[email protected]>
Introduce a new struct MigrateInfo which contains the data to be migrated from stage2 to svsm kernel. Signed-off-by: Vasant Karasulli <[email protected]>
This feature can be used to enable printing log messages to console in addition to storing them in the log buffer. Use ENABLE_CONSOLE_LOG=1 to enable this feature. By default, this feature is disabled for release builds and enabled for debug builds. Signed-off-by: Vasant Karasulli <[email protected]>
Test the log_buffer by calling methods like write_log() and read_log(). Signed-off-by: Vasant Karasulli <[email protected]>
ebb7b14
to
45c52f8
Compare
Implemented a global buffer to store log messages and passed this buffer from stage2 to svsm kernel. Replaced console logging with buffer logging.
Percpu line buffer will probably be necessary, and is not yet implemented. As a rust newbee, I appreciate your feedback on if I am using the right data structures in the right way. Thanks!